#-*- encoding: utf-8 -*-
'''
Created on 2011-9-23

@author: 吴波涛
'''

import cx_Oracle
from dbutil import openConnection


class BasicService():
    
    def __enter__(self):
        self.db = openConnection()
        self.cursor = self.db.cursor()
        return self 
    
    def __exit__(self, *args):
        self.cursor.close()
        self.db.close()


class UserService(BasicService): 
    
    def login(self, username, password, appkey):
        ret = self.cursor.var(cx_Oracle.NUMBER)
        type = self.cursor.var(cx_Oracle.NUMBER)
        data = self.cursor.callproc('Pkg_Ih_User.Sp_Ih_User_Login', [username, password, appkey, ret, type]) 
        
        ret_num = int(data[3])
        type_num = int(data[4])
        
        return (ret_num, type_num)
    
    def register(self):
        return 'register'


class TestService(BasicService):
    
    def get_result(self, input):
        ret = self.cursor.var(cx_Oracle.NUMBER)
        data = self.cursor.callproc('lbs_pkg_test.test_proc', [input, ret])
        ret_str = data[1]
        
        return ret_str
        

if __name__ == '__main__':
    with UserService() as us:
        data = us.login('a', 'b', 'c')
        print data

#    with TestService() as us:
#        data = us.get_result("1")
#        print data
